<?php

namespace app\admin\model\order;

use think\Model;
use traits\model\SoftDelete;

class Refund extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'order_refund';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'refund_type_text',
        'status_text',
        'goods_status_text',
    ];
    

    
    public function getRefundTypeList()
    {
        return ['1' => __('退货退款'), '2' => __('仅退款')];
    }

    public function getStatusList()
    {
        return ['1' => __('审核中'), '2' => __('审核失败'), '3' => __('退款成功')];
    }
    public function getGoodsStatusList()
    {
        return ['1' => __('已签收'), '2' => __('未签收')];
    }


    public function getRefundTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['refund_type'] ?? '');
        $list = $this->getRefundTypeList();
        return $list[$value] ?? '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }

    public function getGoodsStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['goods_status'] ?? '');
        $list = $this->getGoodsStatusList();
        return $list[$value] ?? '';
    }




    public function order()
    {
        return $this->belongsTo('app\admin\model\Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
